import { Injectable, Injector } from '@angular/core';
import { Router } from '@angular/router';


@Injectable()
export class HttpError {

  constructor(private injector: Injector,) {
  }


  //处理各种致命错误
  handleError(err: any): void {
    const router = this.injector.get(Router);

    //401错误时,去登录
    if (err.status === 401) {
      router.navigate(['/signin'],{skipLocationChange:true});
    }
    if (err.status === 500) {

    }
    //409，去绑定手机号
    if (err.status === 409) {
      router.navigate(['/phone'],{skipLocationChange:true});
    }

    //410，去完善学校信息
    if (err.status === 410) {
      router.navigate(['/school'],{skipLocationChange:true});
    }


  }


}